package com.example.bootcurriculumproject.controller;

import com.example.bootcurriculumproject.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    //修改状态
    @PutMapping("/state")
    @ResponseBody
    @CrossOrigin
    public boolean updateState(@RequestParam String consignmentnum){
        orderService.updateStatus(consignmentnum);
        return true;
    }
    //查询所有订单
    @GetMapping("/all")
    @ResponseBody
    @CrossOrigin
    public List selectAll(){
        return orderService.selectOrders();
    }
    //查询已发货订单
    @GetMapping("/out")
    @ResponseBody
    @CrossOrigin
    public List selectOut(){
        return orderService.selectAboutState(1);
    }
    //查询未发货订单
    @GetMapping("/notOut")
    @ResponseBody
    @CrossOrigin
    public List selectNotOut(){
        return orderService.selectAboutState(0);
    }
    //删除当前用户所以订单
    @DeleteMapping("deleteAll")
    @ResponseBody
    @CrossOrigin
    public boolean deleteAll(@RequestParam String uid){
        orderService.deleteAll(uid);
        return true;
    }
    //删除单条订单
    @DeleteMapping("deleteOne")
    @ResponseBody
    @CrossOrigin
    public boolean deleteOneOrder(@RequestParam String consignmentnum){
        orderService.deleteOne(consignmentnum);
        return true;
    }
    //更改送货地址
    @PostMapping("updateAddress")
    @ResponseBody
    @CrossOrigin
    public boolean updateAddress(@RequestParam("address")int address,@RequestParam("orderId")String orderId){
        orderService.updateAddress(address,orderId);
        return true;
    }
}
